package z1info

import (
	"fmt"
	"time"
)

var (
	Version       string
	Commit        string
	BuildTime     string
	BuildTool     string
	BuildPlatform string
)

var BuildInfo string

func init() {
	BuildInfo = fmt.Sprintln(`---------------------- z1info ----------------------`)
	BuildInfo += fmt.Sprintln(`| Version:`, Version)
	BuildInfo += fmt.Sprintln(`| Commit:`, Commit)
	BuildInfo += fmt.Sprintln(`| BuildTime:`, BuildTime)
	BuildInfo += fmt.Sprintln(`| BuildTool:`, BuildTool)
	BuildInfo += fmt.Sprintln(`| BuildPlatform:`, BuildPlatform)
	BuildInfo += fmt.Sprintf(`---------------------- %v ---------`, time.Now().Format("2006-01-02 15:04:05"))
}

// ShowBuildInfo show build infos.
// usage eg: go build -ldflags "-X gitee.com/z1gotool/z1info.Version=`git describe --tags --abbrev=0` -X gitee.com/z1gotool/z1info.Commit=`git rev-parse HEAD` -X gitee.com/z1gotool/z1info.BuildTime=`date +%Y-%m-%dT%H:%M:%S` -X gitee.com/z1gotool/z1info.BuildTool=`echo $(go env GOVERSION)` -X gitee.com/z1gotool/z1info.BuildPlatform=`echo $(go env GOOS)/$(go env GOARCH)`"
func ShowBuildInfo() {
	/*
		go build -ldflags "-X gitee.com/z1gotool/z1info.Version=`git describe --tags --abbrev=0` -X gitee.com/z1gotool/z1info.Commit=`git rev-parse HEAD` -X gitee.com/z1gotool/z1info.BuildTime=`date +%Y-%m-%dT%H:%M:%S` -X gitee.com/z1gotool/z1info.BuildTool=`echo $(go env GOVERSION)` -X gitee.com/z1gotool/z1info.BuildPlatform=`echo $(go env GOOS)/$(go env GOARCH)`"

        GOOS=linux/windows \
        GOARCH=amd64/386 \
		go build \
		-ldflags " \
		-X gitee.com/z1gotool/z1info.Version=`git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"` \
		-X gitee.com/z1gotool/z1info.Commit=`git rev-parse HEAD` \
		-X gitee.com/z1gotool/z1info.BuildTime=`date +%Y-%m-%dT%H:%M:%S` \
		-X gitee.com/z1gotool/z1info.BuildTool=`echo $(go env GOVERSION)` \
		-X gitee.com/z1gotool/z1info.BuildPlatform=`echo $(go env GOOS)/$(go env GOARCH)` \
		"

		go build \
		-ldflags " \
		-X gitee.com/z1gotool/z1info.Version=v1.2.3 \
		-X gitee.com/z1gotool/z1info.Commit=`git rev-parse HEAD` \
		-X gitee.com/z1gotool/z1info.BuildTime=`date +%Y-%m-%dT%H:%M:%S` \
		-X gitee.com/z1gotool/z1info.BuildTool=`echo $(go env GOVERSION)` \
		-X gitee.com/z1gotool/z1info.BuildPlatform=`echo $(go env GOOS)/$(go env GOARCH)` \
		"
	*/

	fmt.Println(BuildInfo)
}
